{% extends 'IcsocUIBundle::page.html.twig' %}
{% from 'IcsocUIBundle:Macro:grid.html.twig' import gridWidth,gridNav,gridConfig,gridKeyword %}
{% block stylesheet %}
    {{ parent() }}
    {% stylesheets
    '@jqgird_css'
    '@gritter_css'
    filter='cssrewrite' filter='uglifycss'
    %}
    <link rel="stylesheet" href="{{ asset_url }}" />
    {% endstylesheets %}
{% endblock %}

{% block content %}
    <table id="grid-table"></table>
    <div id="grid-pager"></div>
{% endblock %}
{% block footer %}
    {% javascripts
    '@jqgird_js'
    '@gritter_js'
    '@common_js'
    filter='uglifyjs'
    %}
    <script src="{{ asset_url }}"></script>
    {% endjavascripts %}
    <script type="text/javascript">
        var param = jsonToString({'start_date':'{{ item.start_date }}','end_date':'{{ item.end_date }}','ag_id':'{{ item.ag_id }}'});
        jQuery(function($) {
            var height = $(document).height() - 150;
            {{ gridWidth() }}
            jQuery(grid_selector).jqGrid({
                caption: "{{ item.caption|trans({'%start_date%': item.start_date, '%end_date%': item.end_date}) }}",
                url: "{{ path('icsoc_report_agent_sign_in_data') }}",
                hidegrid:false,
                postData: {'param':param},
                mtype: 'POST',
                datatype: "json",
                colModel:[
                    {name :"ag_id", index:'ag_id', title : false, formatter : actFormatter, label: '操作' , width:80, sortable:false,align:'center',fixed:true},
                    {name:'ag_num' , index:'ag_num' , label: '坐席工号' , width:80 , sortable:false,align:'center',fixed:true },
                    {name:'ag_name' , index:'ag_name' , label: '坐席名称' , width:80 , sortable:false,align:'center',fixed:true },
                    {name:'sum' , index:'sum' , label: '工作天数(天)' , width:100 , sortable:false,align:'center',fixed:true },
                    {name:'login_hour' , index:'login_hour' , label: '登录时长 (h)' ,width:100, sortable:false,align:'center',fixed:true },
                    {name:'ready_hour' , index:'ready_hour' , label: '空闲时长 (h)' ,width:100, sortable:false,align:'center',fixed:true },
                    {name:'busy_hour' , index:'busy_hour' , label: '总示忙时长 (h)' ,width:100, sortable:false,align:'center',fixed:true },
                    {% if item is not empty %}
                    {% for val in title %}
                        {name: '{{ val.field }}', index: '{{ val.field }}', label: '{{ val.text|trans }}', frozen: true, width: '{{ val.width }}', align: 'center', sortable: false, fixed:true},
                    {% endfor %}
                    {% endif %}
                ],
                {{ gridConfig(true) }}
                height: height,
                rownumWidth: 40,
                rowNum: -1,
                viewrecords: true,
                shrinkToFit:true,
                sortname:"rep_date",
                sortorder:'desc',
                multiselect: false,
                rownumbers: true,
                footerrow:true,
                userDataOnFooter:true
            });
            {{ gridNav(false,false,false,false,true,false) }}
            jQuery(grid_selector).navButtonAdd(
                    pager_selector,
                    {
                        caption:'{{ 'Export Csv'|trans }}',
                        buttonicon:'ace-icon fa fa-file-excel-o  primary',
                        onClickButton:function() {
                            location.href = "{{ path('icsoc_report_agent_sign_in_data')}}?export=csv&param="+param;
                        }
                    }
            ).navButtonAdd(
                    pager_selector,
                    {
                        caption:'{{ 'Export Excel'|trans }}',
                        buttonicon:'ace-icon fa fa-file-excel-o  primary',
                        onClickButton:function() {
                            location.href = "{{ path('icsoc_report_agent_sign_in_data')}}?export=excel&param="+param;
                        }
                    }
            ).navButtonAdd(
                    pager_selector,
                    {
                        caption:'{{ 'Go Back'|trans }}',
                        buttonicon:'ace-icon fa fa-reply  primary',
                        onClickButton:function() {
                            history.back()
                        }
                    }
            );
            function actFormatter(cellvalue, options, rawObject) {
                var detail = '<button type="button" class="btn btn-white btn-pink btn-sm" onclick="showSignIn(\''+rawObject.ag_id+'\',\'{{ item.start_date }}\',\'{{ item.end_date }}\')">查看</button>';
                return  detail;
            }
        });
        function showSignIn(agId,start,end) {
            window.parent.createTab('坐席签到明细', '{{ path('icsoc_report_agent_sign_in_detail')}}?ag_id='+agId+'&start_date='+start+'&end_date='+end);
        }
    </script>
{% endblock %}